home *** CD-ROM | disk | FTP | other *** search
- Path: news.informatik.uni-kiel.de!ma
- From: ma@informatik.uni-kiel.de (Martin Ameskamp)
- Newsgroups: comp.lang.c++
- Subject: Null pointers again (Was: Is this a memory leak?)
- Date: 5 Apr 1996 15:41:38 GMT
- Organization: Dept. of Computer Science, University of Kiel, FRG
- Message-ID: <4k3evi$rpn@gutemine.informatik.uni-kiel.de>
- References: <4jv214$gv7@insosf1.netins.net> <4k02v5$tu7@grimsel.zurich.ibm.com> <4k2vku$s82@werple.net.au> <4k39f5$lhn@grimsel.zurich.ibm.com>
- NNTP-Posting-Host: rigel.informatik.uni-kiel.de
-
- In <4k39f5$lhn@grimsel.zurich.ibm.com> wgk@zurich.ibm.com (Keith Whittingham) writes:
- >>The use of 0 as a pointer is not the address 0x000. It is a null pointer
- >>as defined by the language. Implementations are not even required to use a
- >>bit pattern of all zeroes as a null pointer. They can use any value they
- >>like, as long as it will not also be used as a real address. Furthermore,
- >>rather than being a quirk of implementation, the language guarantees that
- >>deleting a null pointer will do nothing.
-
- Correct.
-
- >Er, I don't think I agree.
-
- >The line of code (if I remember correctly) was:
-
- > bury = 0;
-
- >'bury' being a pointer to some element. bury *is* a pointer and it is
- >assigned the value 0. 0 is the same as 0x0000. The line of code:
-
- > bury = NULL;
-
- >may of course set bury to some other value.
-
- No. 0 is special in regard to pointers (regardless of the spelling,
- be it 0, 0x000 or NULL (beware of casts with NULL)). Instead of
- arguing, I'll quote the ARM (4.6, pointer conversions):
-
- "A constant expression that evaluates to zero is converted to
- a pointer, commonly called the null pointer. It is guaranteed
- that this value will produce a pointer distinguishable from a
- pointer to any object or function."
-
- Annotation: "Note that the null pointer need not be represented
- by the same bit pattern as the integer 0."
-
- >In the real world most, if not all, compilers (I know of no exceptions)
- >use the value 0 for a NULL pointer. As the original poster is trying
- >to understand why his compiler is behaving the way it is I don't think
- >that things need to be complicated with pathological cases.
-
- See section 5.17 of the comp.lang.c FAQ for a long list of machines
- that do not represent the null pointer as aal zeroes.
- (The only topic of section 5 is null pointers from all angles,
- it can be found at
- ftp://rtfm.mit.edu/pub/usenet-by-hierarchy/comp/lang/c/C-FAQ-list)
- (Yes, I know this is compl.lang.c++...)
-
- Martin
-